/*
 * @Author: chunlai
 * @Date: 2025-07-17 15:04:32
 * @LastEditTime: 2025-09-05 08:41:15
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @FilePath: \02.bldinsure\src\mixins\smscode.js
 * @Description: 短信验证码
 */
import { checkPhoneSmsCode } from "@/methods/apis.js";
export const smsCodeMixin = {
  data() {
    return {};
  },
  computed: {},
  mounted() {
    this.$nextTick(() => {
      this.checkSmsCodeStauts();
    });
  },
  methods: {
    async checkSmsCode() {
      if (!this.userInfo.validCode) {
        this.$toast("请输入短信验证码");
        return { status: false };
      }
      // 校验短信验证码
      this.$store.commit("updateLoad", true);
      let res = await checkPhoneSmsCode(
        this.userInfo.phone,
        this.userInfo.validCode
      );
      this.$store.commit("updateLoad", false);
      if (res.code == "1") {
        this.changeData({
          validCode: this.userInfo.validCode,
        });
        return { status: true };
      } else {
        this.$msAlert(res.msg || "短信验证码输入错误");
        return { status: false };
      }
    },
    checkSmsCodeStauts() {
      if (this.userType == "被保险人") {
        if (this.needSmsCheck) {
          this.$nextTick(() => {
            this.$refs.smsCodeRef.initModal(this.userInfo, this.userFlag);
          });
        }
      } else {
        if (this.infoReg.hasOwnProperty("validCode")) {
          this.$nextTick(() => {
            this.$refs.smsCodeRef.initModal(this.userInfo, this.userFlag);
          });
        }
      }
    },
  },
};
